package com.foreknow.dao.impl;

import com.foreknow.dao.AdminDAO;
import com.foreknow.mapping.EntityMapping;
import com.foreknow.mapping.MappingFactory;
import com.foreknow.model.Admin;

import java.sql.SQLException;
import java.util.List;

public class AdminDAOImpl extends BaseDAO implements AdminDAO {
    @Override
    public Admin isCheckLogin(String username, String password) throws SQLException {
        String sql = "select * from admin where username = ? and password=?";
        EntityMapping mapping = this.mappingFactory.getMap(MappingFactory.ADMIN_MAPPING);
        List<Object> list = jdbcTemplate.query(sql, mapping, username, password);
        if (list.size() > 0) {
            return (Admin) list.get(0);
        } else {
            return null;
        }
    }

    @Override
    public boolean getUsernmaeByUser(String username) throws SQLException {
        String sql="select * from admin where username=?";
        EntityMapping mapping=mappingFactory.getMap(MappingFactory.ADMIN_MAPPING);
        List<Object> list=jdbcTemplate.query(sql,mapping,username);
        if (list.size()!=0){
            return true;
        }else {
            return false;
        }
    }
}
